package com.git.bds.mr.login.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.git.bds.mr.login.model.dto.LoginDTO;
import com.git.bds.mr.login.service.user.LoginService;
import com.git.bds.mr.login.valid.ValidGroup;
import com.git.bds.mr.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 成大事
 * @since 2022-09-17 21:05:28
 */
@Api(tags = "登录管理")
@Slf4j
@Validated
@RestController
@RequestMapping("/login")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class LoginController {

    private final LoginService userService;


    @PostMapping("/user")
    @ApiOperation("普通用户 登录")
    public String userLogin(@Validated({ValidGroup.PubUser.class}) @RequestBody LoginDTO info){
       return userService.userLogin(info);
    }

    @PostMapping("/doctor")
    @ApiOperation("医生 登录")
    public String doctorLogin(@Validated({ValidGroup.Doctor.class})  @RequestBody LoginDTO info){
       return userService.doctorLogin(info);
    }

    @PostMapping("/hospital")
    @ApiOperation("医院 登录")
    public String hospitalLogin(@Validated({ValidGroup.Hospital.class})  @RequestBody LoginDTO info){
        return userService.hospitalLogin(info);
    }

    @ApiOperation("退出登录")
    @PostMapping("/logOut")
    public R<Boolean> logOut(){
        StpUtil.logout();
        return R.decide(true);
    }

    @ApiOperation("测试")
    @GetMapping("/test")
    public String test(){
        return "hello world;";
    }



}
